<template>
  <el-dialog
    :visible.sync="param.visible"
    title="修改用户"
    center
    @close="param.close"
    :close-on-click-modal="false"
  >
    <Form1
      ref="editForm"
      :rules="rules"
      :form="editForm"
      :items="items"
      :save="doUpdate"
    >
    </Form1>
    <!-- <el-form
      ref="editForm"
      :model="editForm"
      :rules="rules"
      label-width="100px"
    >
      <el-form-item label="用户名：" prop="userName">
        <el-input
          :clearable="true"
          v-model="editForm.userName"
          placeholder="请输入用户名"
        ></el-input>
      </el-form-item>
      <el-form-item label="姓名：" prop="name">
        <el-input
          :clearable="true"
          v-model="editForm.name"
          placeholder="请输入姓名"
        ></el-input>
      </el-form-item>
      <el-form-item label="密码：" prop="password">
        <el-input
          :clearable="true"
          v-model="editForm.password"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          size="small"
          icon="el-icon-circle-close"
          @click="param.visible = false"
          >取消修改</el-button
        >
        <el-button
          size="small"
          icon="el-icon-circle-check"
          type="primary"
          @click="doUpdate"
          >保存</el-button
        >
      </el-form-item>
    </el-form> -->
  </el-dialog>
</template>
<script>
import Form1 from "@/components/Form1.vue";

export default {
  name: "Edit",
  components: { Form1 },

  props: {
    param: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      editForm: {
        id: null,
        userName: "",
        name: "",
        password: "",
      },
      //验证规则
      rules: {
        userName: [{ required: true, message: "用户名不能为空" }],
        name: [{ required: true, message: "姓名不能为空" }],
        password: [{ required: true, message: "密码不能为空" }],
      },
      items: [
        {
          type: "text",
          label: "用户名：",
          prop: "userName",
          name: "userName",
          placeholder: "请输入用户名",
        },
        {
          type: "text",
          label: "姓名：",
          prop: "name",
          name: "name",
          placeholder: "请输入姓名",
        },
        {
          type: "password",
          label: "密码：",
          prop: "password",
          name: "password",
          placeholder: "请输入姓名密码",
        },
      ],
    };
  },
  mounted() {
    this.editForm = JSON.parse(JSON.stringify(this.param.editForm)); //避免俩对象指向同一个地址
  },
  methods: {
    //   修改
    doUpdate() {
      let flag = this.$refs["editForm"].validateForm();
      if (flag) {
        //   保存
        this.putRequest("/user/", this.editForm).then((res) => {
          if (res) {
            this.$message.success(res.message);
            this.param.close(); //关闭
            this.param.callback(); //重新查询
          }
        });
      }
    },
  },
};
</script>
<style></style>
